// pages/recoveryList/recoveryList.js
import { getActive } from '../../utils/api.js';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    activeParams: {
      page: 1,
      pageSize: 10,
      recommend_type: 0
    },
    navbar:'',
    navbar_id: '',
    more:false,
    activeList:[],
    total:0
  },
  scrollToLower: function (e) {
    if (this.data.more){
      return;
    }
    this.setData({
      activeParams: {
        page: this.data.activeParams.page+1,
        pageSize: 10,
        recommend_type: 0
      }
    })
    this.getData();
  },
  /**
   * 生命周期函数--监听页面加载
   */
  getData(){
    let params = { ...this.data.activeParams, navbar: this.data.navbar, navbar_id: this.data.navbar_id}
    getActive(params).then(res => {
      this.setData({
        activeList: this.data.activeList.concat(res.data.list),
        total:res.data.total
      })
      if (this.data.total == this.data.activeList.length) {
        this.setData({
          more: true
        })
      }
    })
  },
  onLoad(options) {    
    this.setData({
      navbar: options.navbar ? options.navbar:'',
      navbar_id: options.navbar_id
    })
    this.getData()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    if (wx.getStorageSync('model2')) {
      wx.setNavigationBarTitle({
        title: wx.getStorageSync('model2')
      })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})